package com.pp.small.user.feign;

import com.pp.small.api.user.bo.UserBo;
import com.pp.small.common.base.BaseResult;
import com.pp.small.user.entity.User;
import com.pp.small.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author pzh
 * @since 2024-12-06 19:16:23
 */
@Slf4j
@RestController
@RequestMapping("/feign/user")
public class UserFeignController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUserByUserName")
    public BaseResult<UserBo> getUserByUserName(@RequestParam(value = "userName") String userName) {
        log.info("根据用户名获取用户信息");
        User user = userService.getUserByUserName(userName);
        if (Objects.isNull(user)) {
            return BaseResult.showFailMsg("用户名或密码错误");
        }

        UserBo userBo = new UserBo();
        BeanUtils.copyProperties(user, userBo);
        return BaseResult.success(userBo);
    }
}
